using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.DirectoryServices;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok.Data;
using Dimok.Data.Database;
using Dimok.Exceptions;

////////////////////////////////////////////////////////////////////////////////////////////////////
// namespace: Dimok.Menu.Admin
//
// summary:	.
////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Dimok.Menu.Admin{

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <summary>	Menu groups. </summary>
	///
	/// <remarks>	Dimon, 12/21/2010. </remarks>
	////////////////////////////////////////////////////////////////////////////////////////////////////

	public class MenuGroups : System.Web.UI.Page{
		protected Literal ltrMenuTree;
		protected Literal ltrMenuGroups;
		protected Literal ltrMenuNS;
		protected HtmlSelect selGroups;
		protected HtmlSelect selNS;

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Event handler. Called by Page for load events. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <exception cref="ClientException">	Thrown when client. </exception>
		///
		/// <param name="sender">	Source of the event. </param>
		/// <param name="e">			Event information. </param>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private void Page_Load(object sender, System.EventArgs e){
			try{
				UserObjectEx uox = new UserObjectEx();
				ADsGroupDS.t_GroupDataTable dtGroupsInADs = uox.GetAllGroupsInNamespace().t_Group;
				dtGroupsInADs.Addt_GroupRow("", "", "","");
				SQLHelperEx.SortTable(dtGroupsInADs, "cn");
				//SQLHelperEx.UpdateDataTable(dtGroupsInADs, uox.db, "SELECT * FROM t_ADsGroup ORDER BY sam");
				WS ws = new WS();
				ltrMenuTree.Text = ws.GetMenuTree("");
				ltrMenuGroups.Text = ws.MenuGroups_Get("",0,"");
				selGroups.DataSource = dtGroupsInADs;// SQLHelperEx.ExecuteDatasetEx(uox.db,"SELECT GroupName FROM t_Groups ORDER BY GroupName");
				selGroups.DataTextField = "cn";
				selGroups.DataValueField = "cn";
				selGroups.DataBind();
				selNS.Items.Add("");
				if( uox.IsInDomain )
					foreach(DirectoryEntry deOU in	ADs.LDAP.FindOUs(uox.NameSpaceOU,SearchScope.OneLevel))
						if( !ADs.Props.CN(deOU).StartsWith("_") )
							selNS.Items.Add(ADs.Props.CN(deOU));
				//selNS.DataSource = SQLHelperEx.ExecuteDatasetEx(uox.db,"SELECT NameSpace FROM t_NameSpace WHERE ParentID=0 ORDER BY NameSpace");
				//selNS.DataTextField = selNS.DataValueField = "NameSpace";
				//selNS.DataBind();
			}catch(Exception exc){ throw new ClientException(exc); }
		}

		#region Web Form Designer generated code

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Raises the initialise event. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="e">	Event information to send to registered event handlers. </param>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	
		/// Required method for Designer support - do not modify the contents of this method with the code
		/// editor. 
		/// </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
